﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace LOGISTCBUS.Entities
{
    public static class Encryption
    {
        #region [ Properties ]

        private const String key = "2Mkey";
        private static byte[] chave = { };
        private static byte[] iv = { 12, 34, 56, 78, 90, 102, 114, 126 };

        #endregion [ Properties ]

        #region [ Public Methods ]

        /// <summary>
        /// Encrypts the MD5.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public static String EncryptMd5(String value)
        {
            var md5 = MD5.Create();
            byte[] data = md5.ComputeHash(Encoding.Default.GetBytes(value));
            var sbString = new StringBuilder();
            for (int i = 0; i < data.Length; i++)
            {
                sbString.Append(data[i].ToString("x2"));
            }
            return sbString.ToString();
        }

        #endregion [ Public Methods ]

        #region [ Public methods ]

        /// <summary>
        /// Encrypts the specified valor.
        /// </summary>
        /// <param name="valor">The valor.</param>
        /// <returns></returns>
        public static String Encrypt(String valor)
        {
            return new RijndaelEnhanced(key).Encrypt(valor);
        }

        /// <summary>
        /// Decrypts the specified valor.
        /// </summary>
        /// <param name="valor">The valor.</param>
        /// <returns></returns>
        public static String Decrypt(String valor)
        {
            return new RijndaelEnhanced(key).Decrypt(valor);
        }
        #endregion [ Public methods ]
    }
}
